package servlet;

import domain.NingboGDP;
import org.json.JSONObject;
import service.NingBoGDPService;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

public class NingBoGDPServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        NingBoGDPService ns = new NingBoGDPService();
        request.setCharacterEncoding("UTF-8");
        NingboGDP nbGDP = ns.selectDataByCounty(request.getParameter("address"));
        JSONObject jsonObj = new JSONObject();
        jsonObj.put("第一产业",nbGDP.getPrimaryIndustry());
        jsonObj.put("第二产业",nbGDP.getSecondaryIndustry());
        jsonObj.put("第三产业",nbGDP.getTertianIndustn());
        jsonObj.put("农林牧渔",nbGDP.getAgriculture());
        jsonObj.put("工业",nbGDP.getIndustiy());
        jsonObj.put("建筑",nbGDP.getConstructions());
        jsonObj.put("批发和零售",nbGDP.getRetail());
        jsonObj.put("交通运输",nbGDP.getTransportation());
        jsonObj.put("住宿餐饮",nbGDP.getHoteling());
        jsonObj.put("信息传输",nbGDP.getSoftware());
        jsonObj.put("金融",nbGDP.getFinancialIndustiy());
        jsonObj.put("房地产",nbGDP.getRealEstateIndustiy());
        jsonObj.put("租赁和商劳",nbGDP.getLeasehold());
        jsonObj.put("科研和技术",nbGDP.getScientificResearch());
        jsonObj.put("水利环境管理",nbGDP.getWater());
        jsonObj.put("居民服务",nbGDP.getResidentialSenice());
        jsonObj.put("教育",nbGDP.getEducation());
        jsonObj.put("社会工作",nbGDP.getHealthCare());
        jsonObj.put("文体娱乐",nbGDP.getCultureSports());
        jsonObj.put("公共管埋",nbGDP.getPublicManagement());
        response.setHeader("content-type","text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        out.println(jsonObj);

    }
}
